package protocol;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhuQi
 * @ClassName Message
 * @Date 2023/1/12 15:05
 * @Version 1.0
 * @Description 所有消息的抽象父类
 */
@Data
public abstract class Message implements Serializable {

	public static Class<? extends Message> getMessageClass(int messageType) {
		return messageClasses.get(messageType);
	}

	private static final Map<Integer, Class<? extends Message>> messageClasses = new HashMap<>();

	private int sequenceId;

	private int messageType;

	public static final int LoginRequestMessage = 0;
	public static final int LoginResponseMessage = 1;
	public static final int ChatRequestMessage = 2;
	public static final int ChatResponseMessage = 3;
	public static final int GroupCreateRequestMessage = 4;
	public static final int GroupCreateResponseMessage = 5;
	public static final int GroupJoinRequestMessage = 6;
	public static final int GroupJoinResponseMessage = 7;
	public static final int GroupQuitRequestMessage = 8;
	public static final int GroupQuitResponseMessage = 9;
	public static final int GroupChatRequestMessage = 10;
	public static final int GroupChatResponseMessage = 11;
	public static final int GroupMembersRequestMessage = 12;
	public static final int GroupMembersResponseMessage = 13;
	public static final int HeartBeatRequestMessage = 14;
	public static final int HeartBeatResponseMessage = 15;
	public static final int PingMessage = 101;
	public static final int PongMessage = 102;

	/**
	 * 请求类型 byte 值
	 */
	public static final int RPC_MESSAGE_TYPE_REQUEST = 101;
	/**
	 * 响应类型 byte 值
	 */
	public static final int RPC_MESSAGE_TYPE_RESPONSE = 102;

	static {
		// 去掉初始化数据
		//		for (MessageClassEnum value : MessageClassEnum.values()) {
		//			messageClasses.put(value.getCode(), value.getClazz());
		//		}
	}
}
